package com.bw.shop2208a

import android.content.Intent
import android.graphics.Color
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.view.animation.LinearInterpolator
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.bw.shop2208a.databinding.ActivityMainBinding
import com.bw.shop2208a.login.LoginActivity
import com.bw.shop2208a.mvvm.BaseViewActivity
import com.bw.shop2208a.utils.Constant
import java.util.Timer
import kotlin.concurrent.timerTask

class WelcomActivity : BaseViewActivity<ActivityMainBinding>() {
    private val timer = Timer()
    private var time: Int = 5
    override fun initViwe() {
        timer.schedule(timerTask {
            runOnUiThread {
                val animation = AnimationUtils.loadAnimation(this@WelcomActivity, R.anim.ani_djs)
                animation.duration = 1000
                animation.repeatMode = Animation.REVERSE
                animation.interpolator = LinearInterpolator()
                when (time--) {
                    5 -> {
                        binding.v1.animation = animation
                        binding.v1.setBackgroundColor(Color.RED)
                    }
                    4 -> {
                        binding.v2.animation = animation
                        binding.v2.setBackgroundColor(Color.RED)
                    }
                    3 -> {
                        binding.v3.animation = animation
                        binding.v3.setBackgroundColor(Color.RED)
                    }
                    2 -> {
                        binding.v4.animation = animation
                        binding.v4.setBackgroundColor(Color.RED)
                    }
                    1 -> {
                        binding.v5.animation = animation
                        binding.v5.setBackgroundColor(Color.RED)
                    }
                }
            }
            if (time == 0) {
                timer.cancel()
                //build()查找路径  navigation 控制页面进行跳转
                ARouter.getInstance().build("/app/main").navigation()
                finish()
            }
        }, 0, 1000)
//        lifecycleScope.launch {
//            for (i in 5 downTo 0) {
//                binding.time = i
//                if (time==0){
//                    startActivity(Intent(this@MainActivity,LoginActivity::class.java))
//                    finish()
//                delay(1000)
//            }
//                binding.user = RegisterParam("","","","http://10.161.9.80:8080/res/icon/27471946bab24665a0b4281c6a010592.jpg"
//                ,"","","","","")
//            }
//        }
    }

    override fun iniData() {

    }

    override fun getLayoutId(): Int = R.layout.activity_main

}